import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";
// import WindiCSS from "vite-plugin-windicss";
export default defineConfig({
  plugins: [vue()],

  resolve: {
    // 设置文件./src路径为 @
    alias: [
      {
        find: "@",
        replacement: resolve(__dirname, "./src"),
      },
    ],
  },
  css: {
    postcss: {
      plugins: [tailwindcss, autoprefixer],
    },
  },
  base: "/index/",
  build: {
    outDir: "index",
    rollupOptions: {
      output: {
        chunkFileNames: "js/[name]-[hash].js",
        entryFileNames: "js/[name]-[hash].js",
        assetFileNames: "[ext]/[name]-[hash].[ext]",
      },
    },
  },

  server: {
    port: 8023, // 端口
    host: "0.0.0.0",
    proxy: {
      "/seller": {
        //请求路径关键字
        //https://nxbcs.yeahshopee.com/
        //https://nxb.xiehewanbang.com/
        target: "https://nxb.xiehewanbang.com/", //对应自己的接口
        changeOrigin: true, //是否允许跨域,在本地会创建一个虚拟服务端，然后发送请求的数据， 
        // 并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
        ws: true,
        rewrite: (path) => path.replace(/^\/seller/, "/seller"),
        // pathRewrite: {
        //   "/phone": "", //这里理解成用‘/api’代替target里面的地址，后面组件中我们掉接口时直接用api代替
        //   // 比如我要调用'http://localhost:8024/management/user/add'，直接写‘/api/user/add’即可
        // },
      },
    },
  },
});
